#ifndef __H_GAME_H__
#define __H_GAME_H__

#include <deque>
#include <vector>
#include <map>
#include <set>
#include "ICC_Timer_Handler.h"
#include "RedisClient.h"
#include "GameBase.h"
#include "DbPart.h"
#include "CClient.h"
#include "def.h"
#include "LogicData.h"
#include "HostBase.h"
#include <thread>
#include <rabbitmq-c/amqp.h>
#include <rabbitmq-c/tcp_socket.h>

class CHost;

const unsigned int g_uid_mod = 100;
const unsigned int g_cache_dur = 129600;

class CGameServer : public BYTimerOject
{
	struct stTransactionsCache
	{
		_u64_ m_lastflowtime;
		unsigned int m_count;

		stTransactionsCache():m_lastflowtime(0), m_count(0)
		{
		}
		stTransactionsCache(const stTransactionsCache& other)
		{
			m_lastflowtime = other.m_lastflowtime;
			m_count = other.m_count;
		}

		stTransactionsCache& operator = (const stTransactionsCache& other)
		{
			if (this == &other)
				return *this;

			m_lastflowtime = other.m_lastflowtime;
			m_count = other.m_count;

			return *this;
		}
	};
public:
	CGameServer();
	virtual ~CGameServer();
public:
	virtual bool InitGame();
	virtual int OnBYTimeOut(int Timerid);
	int ProcessPacket(SocketHandler * pHandler, NETInputPacket* inputPkg);
	int ProcEventPublishService(int ev_id, SpiderEvent* pEvent);
	int ProcEventGameInit(int ev_id, SpiderEvent* pEvent);
private:
	void run(void);
	int procMessage(const char* data, const unsigned int len);
	bool initmq(void);
	bool mqbind(void);
	void releasemq(void);
	bool ReadCommonConf(const char* strxml);
	int procTimerCacheCheck(void);
	void chachCheck(void);

	std::map<std::string, _u64_> m_tables;

	std::thread* m_pthread;
	unsigned int m_nodecount;
	int m_nodeindex;
	volatile bool m_exitflag;
	std::string m_mqIp;
	unsigned short m_mqPort;
	std::string m_mqVhost;
	std::string m_mqUsername;
	std::string m_mqPwd;
	amqp_connection_state_t m_mqconn;
	int m_mqchannel;
	static char* s_szexchange;
	static char* s_szqueue;

	bool m_initflag;
	volatile bool m_cachecheckflag;
public:
	CHost* m_pHost;
	CDbPart m_dbHandler;
	//CDbPart m_dbHandlerAssistant;
};


#endif


